#include "Gui.h"
#include <iostream>
#include <sstream>
#include <string> 

Gui::Gui() {
}


Gui::~Gui() {
}
	

void Gui::Initialize(sf::RenderWindow* window) {
	m_renderWindow = window;
	m_hp = 0;
	m_score = 0;

	m_font = new sf::Font();
	m_font->loadFromFile("Assets/Fonts/DEFTONE.ttf");

	m_fullHeartTexture = new sf::Texture;
	m_fullHeartTexture->loadFromFile("Assets/Images/Full_Heart.png");
	m_halfHeartTexture = new sf::Texture;
	m_halfHeartTexture->loadFromFile("Assets/Images/Empty_Heart.png");

	m_hearSprite1 = new sf::Sprite;
	m_hearSprite2 = new sf::Sprite;
	m_hearSprite3 = new sf::Sprite;
	m_hearSprite4 = new sf::Sprite;
	m_hearSprite5 = new sf::Sprite;

	m_hearSprite1->setTexture(*m_fullHeartTexture);
	m_hearSprite2->setTexture(*m_fullHeartTexture);
	m_hearSprite3->setTexture(*m_fullHeartTexture);
	m_hearSprite4->setTexture(*m_fullHeartTexture);
	m_hearSprite5->setTexture(*m_fullHeartTexture);


	m_scoreText = new sf::Text();
	m_scoreText->setFont(*m_font);
	m_scoreText->setString("Score:");
	m_scoreText->setCharacterSize(90);
	m_scoreText->setColor(sf::Color(255,198,1,255));

	m_scoreNr = new sf::Text();
	m_scoreNr->setFont(*m_font);
	m_scoreNr->setCharacterSize(90);
	m_scoreNr->setColor(sf::Color(255,198,1,255));
}


void Gui::Update(Player* player, float CameraX) {
	m_hearSprite1->setPosition(player->getSprite()->getPosition().x- 650, 100.f);
	m_hearSprite2->setPosition(player->getSprite()->getPosition().x- 550, 100.f);
	m_hearSprite3->setPosition(player->getSprite()->getPosition().x- 450, 100.f);
	m_hearSprite4->setPosition(player->getSprite()->getPosition().x- 350, 100.f);
	m_hearSprite5->setPosition(player->getSprite()->getPosition().x- 250, 100.f);

	std::stringstream ss2;
	ss2 << player->getScore();
	std::string str2 = ss2.str();
	m_scoreNr->setString(str2);

	m_scoreNr->setPosition(player->getSprite()->getPosition().x + 520, 70.f);
	m_scoreText->setPosition(player->getSprite()->getPosition().x + 320, 70.f);

	if(player->getHP() == 50){
		m_hearSprite1->setTexture(*m_fullHeartTexture);
		m_hearSprite2->setTexture(*m_fullHeartTexture);
		m_hearSprite3->setTexture(*m_fullHeartTexture);
		m_hearSprite4->setTexture(*m_fullHeartTexture);
		m_hearSprite5->setTexture(*m_fullHeartTexture);
	}else if(player->getHP() == 40){
		m_hearSprite1->setTexture(*m_fullHeartTexture);
		m_hearSprite2->setTexture(*m_fullHeartTexture);
		m_hearSprite3->setTexture(*m_fullHeartTexture);
		m_hearSprite4->setTexture(*m_fullHeartTexture);
		m_hearSprite5->setTexture(*m_halfHeartTexture);
	}else if(player->getHP() == 30){
		m_hearSprite1->setTexture(*m_fullHeartTexture);
		m_hearSprite2->setTexture(*m_fullHeartTexture);
		m_hearSprite3->setTexture(*m_fullHeartTexture);
		m_hearSprite4->setTexture(*m_halfHeartTexture);
		m_hearSprite5->setTexture(*m_halfHeartTexture);
	}else if(player->getHP() == 20){
		m_hearSprite1->setTexture(*m_fullHeartTexture);
		m_hearSprite2->setTexture(*m_fullHeartTexture);
		m_hearSprite3->setTexture(*m_halfHeartTexture);
		m_hearSprite4->setTexture(*m_halfHeartTexture);
		m_hearSprite5->setTexture(*m_halfHeartTexture);
	}else if(player->getHP() == 10){
		m_hearSprite1->setTexture(*m_fullHeartTexture);
		m_hearSprite2->setTexture(*m_halfHeartTexture);
		m_hearSprite3->setTexture(*m_halfHeartTexture);
		m_hearSprite4->setTexture(*m_halfHeartTexture);
		m_hearSprite5->setTexture(*m_halfHeartTexture);
	}

	m_renderWindow->draw(*m_hearSprite1);
	m_renderWindow->draw(*m_hearSprite2);
	m_renderWindow->draw(*m_hearSprite3);
	m_renderWindow->draw(*m_hearSprite4);
	m_renderWindow->draw(*m_hearSprite5);

	m_renderWindow->draw(*m_scoreNr);
	m_renderWindow->draw(*m_scoreText);
}


void Gui::Cleanup() {
	delete m_font;
	delete m_hearSprite1;
	delete m_hearSprite2;
	delete m_hearSprite3;
	delete m_hearSprite4;
	delete m_hearSprite5;
	delete m_fullHeartTexture;
	delete m_halfHeartTexture;
}
